package top.zk123.chain.config;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import top.zk123.chain.bean.Certificate;
import top.zk123.chain.mapper.CertificateMapper;

import javax.annotation.Resource;
import java.util.List;

@Component
public class ScheduledTasks {
    @Resource
    CertificateMapper certificateMapper;

    /**
     * 定时器更新证书上链状态
     */
    @Scheduled(fixedDelay = 15000)
    void upload2chain() {
        List<Certificate> certList = certificateMapper.findByCertState(1);
        for (Certificate certificate : certList) {
            certificate.setCertState(2);
            certificateMapper.save(certificate);
        }
    }
}
